package com.atguigu.myzhxy.controller;

import com.atguigu.myzhxy.pojo.Clazz;
import com.atguigu.myzhxy.service.ClazzService;
import com.atguigu.myzhxy.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * ClassName: ClazzController
 * Package: com.atguigu.myzhxy.controller
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-01-12
 * Time: 15:41
 */
@Api(tags = "班级管理器")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    //sms/clazzController/getClazzs
    @ApiOperation("/查询所有班级的信息")
    @GetMapping("/getClazzs")
    public Result getClazzs(){
        List<Clazz> clazzes = clazzService.getClzzs();
        return Result.ok(clazzes);
    }


    //sms/clazzController/deleteClazz
    @ApiOperation("删除单个或多个班级的方法")
    @DeleteMapping("/deleteClazz")
    public Result deleteClazz(@ApiParam("要删除多个班级ID的JSON数组") @RequestBody List<Integer> ids){

        clazzService.removeByIds(ids);
        return Result.ok();
    }

    //sms/clazzController/saveOrUpdateClazz

    @ApiOperation("/增加或者修改班级")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(
            @ApiParam("JSON格式的班级信息") @RequestBody Clazz clazz
    ){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }

    //sms/clazzController/getClazzsByOpr/1/3
    @ApiOperation("分页带条件查询班级信息")
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzsByOpr(
            @ApiParam("分页查询的页码数") @PathVariable("pageNo") Integer pageNo,
            @ApiParam("分页查询的大小") @PathVariable("pageSize") Integer pageSize,
            @ApiParam("分页查询的查询条件") Clazz clazz
    ){
        Page<Clazz> page = new Page<>(pageNo,pageSize);

        IPage<Clazz> iPage = clazzService.getClazzByOpr(page,clazz);

        return Result.ok(iPage);
    }
}
